package leetcode;

import util.Tree;
import util.TreeNode;

/**
 * @Project : AlgorithmLearning
 * @Package : Leetcode
 * @File : Q0101.java
 * @Author : WangRuoyu
 * @Date 2023/10/22 20:17
 */

public class Q0101 {
    private boolean isSame(TreeNode left, TreeNode right) {
        if (left == null && right == null) return true;
        if (left == null || right == null) return false;
        return left.val == right.val && isSame(left.left, right.right) && isSame(left.right, right.left);
    }

    public boolean isSymmetric(TreeNode root) {
        if (root == null) return true;
        else return isSame(root.left, root.right);
    }

    public static void main(String[] args) {
        Q0101 sl = new Q0101();
        String[] tree = {"1", "2", "3", null, null, "4", null, null, "2", "4", null, null, "3", null, null};
        TreeNode root = Tree.createTreeByPreorder(tree);
        System.out.println(sl.isSymmetric(root));
    }
}